package com.huike.web.controller.review;


import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import com.huike.review.vo.MybatisReviewVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 该Controller主要是为了复习三层架构以及Mybatis使用的，该部分接口已经放开权限，可以直接访问
 * 同学们在此处编写接口通过浏览器访问看是否能完成最简单的增删改查
 */
@RestController
@RequestMapping("/review")
public class MybatisReviewController extends BaseController {

    @Autowired
    private ReviewService reviewService;

    @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult saveData(@PathVariable("name")String name, @PathVariable("age")String age, @PathVariable("sex")String sex){
        int row = reviewService.saveData(name,age,sex);
        return AjaxResult.success(row);
    }

    @PostMapping("/saveData")
    public AjaxResult saveData(@RequestBody MybatisReviewVO mybatisReviewVO){
        int row = reviewService.saveData(mybatisReviewVO);
        return AjaxResult.success(row);
    }

    @PostMapping("/update")
    public AjaxResult update(@RequestBody MybatisReviewVO mybatisReviewVO){
        int row = reviewService.update(mybatisReviewVO);
        return AjaxResult.success(row);
    }

    @DeleteMapping("/remove{id}")
    public AjaxResult remove(@PathVariable("id")Long id){
        int row = reviewService.remove(id);
        return AjaxResult.success(row);
    }

    @GetMapping("/getById{id}")
    public AjaxResult getById(@PathVariable("id")Long id){
        Review row = reviewService.getById(id);
        return AjaxResult.success(row);


    }
}